package com.sduept.nwld.dataview.controller.message;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;

import org.primefaces.PrimeFaces;
import org.springframework.beans.factory.annotation.Autowired;

import com.sduept.bigdata.web.jsf.controller.AbstractController;
import com.sduept.core.dao.SuperDAO;
import com.sduept.nwld.dataserver.manager.message.UserMessageManager;
import com.sduept.permission.entity.PersonnelEntityBean;

@Named
@ViewScoped
public class MessageSubscribeController extends AbstractController {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3234306566529593019L;
	@Autowired
	private UserMessageManager service;
	@Autowired
	private SuperDAO dao;
	private PersonnelEntityBean	user;
	private List<UserSubscribedTopicDto> userTopicList;
	@PostConstruct
	public void init(){
		user = getCurrentUser();
		userTopicList = service.getUserSubscribedTopicDtos(user);
	}
	public void checkListener(UserSubscribedTopicDto dto){
		if(dto.isCheck())
			dto.setCheck(false);
		else 
			dto.setCheck(true);
	}
	public void saveUserSubscriptionInfo(){
		for(UserSubscribedTopicDto dto:userTopicList){
			service.saveUserSubscriptionInfo(dto, user);
		}
		PrimeFaces.current().dialog().closeDynamic(null);
	}
	public List<UserSubscribedTopicDto> getUserTopicList() {
		return userTopicList;
	}

	public void setUserTopicList(List<UserSubscribedTopicDto> userTopicList) {
		this.userTopicList = userTopicList;
	}
	public void closeDialog(){
		PrimeFaces.current().dialog().closeDynamic(null);
	}
}
